/*
 * © 2010 Autodata Solutions Company. All Rights Reserved
 * This source code is the confidential and proprietary information of Autodata Solutions Company.
 * The user shall not, in whole or in part, copy, publish, disclose or make any use of this source code
 * without the prior written consent of Autodata Solutions Company.
 */
Ext.ns('net.autodata.modelwalk.TrimComboBox');
(function() {

    var Reader = function() {
        return new Ext.data.JsonReader({
            idProperty: 'code',
            root: '',
            fields: [
                { name: 'code' },
                { name: 'description', sortType: Ext.data.SortTypes.asUCString },
                { name: 'msrp' },
                { name: 'imageName' }
            ]
        });
    };

    /**
    * @class TrimComboBox
    * @extends net.autodata..form.DependentComboBox
    * @namespace net.autodata.modelwalk
    */
    var TrimComboBox = Ext.extend(net.autodata.form.DependentComboBox, {

        /**
        * @property proxyCfg
        * @type Object
        */
        proxyCfg: {
            url: String.format('{0}/Ajax/ModelWalk/Trims/', ASC.cfg.getLocaleContextPath())
        },

        /**
        * xtype = acompare-mw-trimcombo
        * @method constructor
        * @param {Object} cfg
        */
        constructor: function(cfg) {
            cfg = cfg || {};

            var storeCfg = cfg.storeCfg || {};
            delete cfg.storeCfg;

            Ext.apply(storeCfg, {
                autoDestroy: true,
                proxy: new net.autodata.modelwalk.data.TrimHttpCacheProxy(this.proxyCfg),
                reader: new Reader()
                
            }, {
                autoLoad: false,
                sortInfo: {
                	field: 'description',
                	direction: 'ASC'
                },
                remoteSort: false
            });

            var store = new net.autodata.data.Store(storeCfg);

            Ext.applyIf(cfg, {
                allowBlank: true,
                emptyText: ASC.message('net.autodata.modelwalk.label.please-select'),
                forceSelection: true,
                lazyInit: false,
                mode: 'local',
                selectOnFocus: true,
                triggerAction: 'all',
                typeAhead: true,
                width: 200,
                minListWidth: 300
            });

            Ext.apply(cfg, {
                displayField: 'description',
                store: store,
                valueField: 'code'
            });


            TrimComboBox.superclass.constructor.call(this, cfg);
        },

        initComponent: function() {
            TrimComboBox.superclass.initComponent.apply(this, arguments);
        }
    });

    net.autodata.modelwalk.TrimComboBox = TrimComboBox;

    Ext.reg('acompare-mw-trimcombo', net.autodata.modelwalk.TrimComboBox);
})();
